package com.arlin.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

/**
 * @ClassName: DeptProviderHystrix8081
 * @Description: TODO
 * @Author: arlin
 * @Date: 2021/3/21
 */
@SpringBootApplication
@EnableEurekaClient //服务启动后自动注册Eureka中
@EnableDiscoveryClient  //服务发现
@EnableCircuitBreaker   //开启对熔断的支持
public class DeptProviderHystrix8081 {
    public static void main(String[] args) {
        SpringApplication.run(DeptProviderHystrix8081.class, args);
    }

    @Bean
    public ServletRegistrationBean hystrixServletRegistrationBean(){    //在spring boot中向servlet容器中注册新的servlet并设置这个servlet的请求url
        ServletRegistrationBean bean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());  //将新的servlet注入servlet容器中
        bean.addUrlMappings("/actuator/hystrix.stream");    //设置该servlet的请求路径
        return bean;
    }
}
